package reflect;

import reflect.annotation.AutoRunClass;

import java.io.File;
import java.net.URISyntaxException;

/**
 * 输出与当前类Test3所在同一个包中那些类被@AutoRunClass标注了?
 */
public class Test3 {
    public static void main(String[] args) throws Exception {
        File dir = new File(
                Test3.class.getResource(".").toURI()
        );
        String packName = Test3.class.getPackage().getName();
        File[] subs = dir.listFiles(f->f.getName().endsWith(".class"));
        for(File sub : subs){
            String fileName = sub.getName();
            String className = fileName.substring(0,fileName.indexOf("."));
            Class cls = Class.forName(packName+"."+className);
            if(cls.isAnnotationPresent(AutoRunClass.class)){
                System.out.println(cls.getName()+"被标注了");
            }
        }
    }
}











